<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>客户管理</el-breadcrumb-item>
      <el-breadcrumb-item>客户活动</el-breadcrumb-item>
      <el-breadcrumb-item>慰问礼</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <el-table  v-loading="loading" :data="clientList" style="width: 100%">
        <el-table-column type="index"> </el-table-column>
        <el-table-column prop="clientName" label="客户名称"> </el-table-column>
        <el-table-column prop="clientName" label="客户名称"> </el-table-column>
        <el-table-column prop="clientMobile" label="客户电话">
        </el-table-column>
        <el-table-column prop="address" label="操作">
          <el-button type="text" @click="dialogVisible = true"
            >赠送慰问礼</el-button
          >
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog
      title="赠送慰问礼"
      :visible.sync="dialogVisible"
      width="40%"
      @close="handleClose"
    >
      <el-form
        :model="sendInfo"
        :rules="sendRule"
        ref="sendRef"
        label-position="top"
        style="padding: 0 50px"
        label-width="80px"
      >
        <el-form-item label="地址" prop="address">
          <el-input v-model="sendInfo.address"></el-input> </el-form-item
      ></el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sendGift">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading:false,
      clientList: [],
      dialogVisible: false,
      sendInfo: { address: "" },
      sendRule: {
        address: [{ required: true, message: "请输入地址", trigger: "blur" }],
      },
    };
  },
  methods: {
    //获取客户信息
    async getClientList() {
      this.loading = true;
      const { data: res } = await this.$http.get("clientUser");
      if (res.status !== 200) return this.$message.error(res.msg);
      this.clientList = res.clientList;
      this.loading = false;
    },
    async sendGift() {
      const confirmResult = await this.$confirm(
        "是否确认赠送慰问礼至该地址？",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).catch((err) => err);
      if (confirmResult != "confirm") return this.$message.info("已取消");
      this.$message.success("已记录数据,仓库将安排寄出!");
      this.dialogVisible = false;
    },
    handleClose() {
      this.$refs.sendRef.resetFields();
    },
  },
  created() {
    this.getClientList();
  },
};
</script>

<style scoped>
.el-card {
  height: 600px;
}
</style>
